﻿using System;
using System.Data;
using System.Collections;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Ysb.Components;
public partial class Admin_UserCalulate : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!AdminCheck.Check(this, 1))
        {
            Response.Redirect(AdminCheck.RedirectPage);
            return;
        }
        if (!Page.IsPostBack)
        {
            selectpaytype.DataSource = new PublicSqlService().GetData("*", "tbl_Paytype", "");
            selectpaytype.DataTextField = "Name";
            selectpaytype.DataValueField = "Name";
            selectpaytype.DataBind();
            anolb.Text = Request.QueryString["ano"].ToString();
            namelb.Text = Request.QueryString["name"].ToString();
            lk.ImageUrl = "~/images/btn-view-list.gif";
            lk.NavigateUrl = "UserPayList.asp?id=" + Request.QueryString["id"].ToString() + "&ano=" + Request.QueryString["ano"] + "&year=" + DateTime.Now.Year.ToString() + "&yue=" + DateTime.Now.Month.ToString();

            DataLoad();

        }
    }

    private void DataLoad()
    {

        string acc = "";
        decimal yingfu = 0;
        decimal yue = 0;
        decimal shangyue = 0;
        decimal benyue = 0;
        bool qf = false;
		
		
		 if (Session["UserName"].ToString() == "Tom Liu" || Session["UserName"].ToString() == "小容" || Session["UserName"].ToString() == "路得" || Session["UserName"].ToString() == "steven" || Session["UserName"].ToString() == "Chris Wu" || Session["UserName"].ToString() == "amy"
   )
                 {
                 }
                 else
                 {
       payall.Attributes.Add("readonly", "readonly");


                 }
				 
        if (new UserService().GetUserPay(Request.QueryString["id"].ToString(), ref acc, ref yingfu, ref yue, ref shangyue, ref benyue, ref qf))
        {
            ViewState["Ano"] = acc;
            yingflb.Text = "";
            yuelb.Text = "";
            shangyuelb.Text = "";
            zhijinlb.Text = "";

        }
        else
        {
            Tools.OpenWindow(this, "数据异常，请误录入！请重新刷新本页");

        }



    }
    protected void payok_Click(object sender, ImageClickEventArgs e)
    {
        if (payall.Value.Trim() == "")
        {
            Tools.OpenWindow(this, "请输入支付总额");
            return;
        }
        Tools t = new Tools();
        Hashtable hs = new Hashtable();

        PublicSqlService ps = new PublicSqlService();
        int i = ps.GetMax("ID", "Tb_Pay", "");

        int all = 20000 + i;
        hs.Add("AccountNo", all.ToString());//流水号
        hs.Add("UserID", Request.QueryString["id"].ToString());
        hs.Add("PayAll", t.StringToDecimalDif(payall.Value.Trim()));


        hs.Add("PayType", selectpaytype.Value);
        hs.Add("ReMark", payabout.Value);
        hs.Add("PayDate", t.StringToTime(paydate.Value));
        hs.Add("PostUser", Session["uid"]);
        hs.Add("PostDate", DateTime.Now);

        if (ps.GetCoun("ID", "Tb_Pay", "AccountNo='" + all.ToString() + "'") > 0)
        {
            Tools.OpenWindow(this, "网络延迟。。账号重复，请重试");
            return;
        }

        if (ps.Insert(hs, "Tb_Pay"))
        {


            Hashtable hs2 = new Hashtable();
            hs2.Clear();
            hs2.Add("admin", Session["UserName"].ToString());
            hs2.Add("Url", Session["url"]);
            hs2.Add("date", DateTime.Now);
            hs2.Add("trackingno", "");
            hs2.Add("type", "paid money");
            hs2.Add("account", Request.QueryString["ano"]);
            hs2.Add("amount", t.StringToDecimalDif(payall.Value.Trim()));
            new PublicSqlService().Insert(hs2, "log");

            Tools.OpenWindow(this, "保存成功", Request.Url.ToString());
        }
        else
        {
            Tools.OpenWindow(this, "保存失败！");
        }

    }
}
